<?php
class Admin_Model_ArticleCategory extends Zend_Db_Table_Abstract{
    protected $_name = 'loai_bai_viet';

    public function getArticleCategory($id){
        $id = (int)$id;
        $row = $this->fetchRow('ma = ' . $id);
        if (!$row) {
            throw new Exception("Không tìm thấy bài viết có mã bằng: $id");
        }
        return $row->toArray();
    }

    public function listarticlecategory(){
        $db = Zend_Registry::get('connectDB');
        $select = $db->select()
                    ->from('loai_bai_viet');
        $result = $db->fetchAll($select);
        return $result;
    }

    public function addArticleCategory($ten, $mo_ta, $ma_loai_cha,  $thu_tu_hien_thi)
    {

        $data = array(
        'ten' => $ten,
        'mo_ta' => $mo_ta,
        'ma_loai_cha' => $ma_loai_cha,
        'thu_tu_hien_thi' => $thu_tu_hien_thi,
        );
        
        $this->insert($data);

    }
    public function updateArticleCategory($ma, $ten, $mo_ta, $ma_loai_cha,  $thu_tu_hien_thi){
        $data = array(
        'ten' => $ten,
        'mo_ta' => $mo_ta,
        'ma_loai_cha'=>$ma_loai_cha,
        'thu_tu_hien_thi' => $thu_tu_hien_thi,
        );
        $this->update($data, 'ma = '. (int)$ma);
    }
    public function deleteArticleCategory($ma){
        $this->delete('ma =' . (int)$ma);
    }
}
 
